package znbkFragment;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.lancooznbk.R;
import com.example.lancooznbk.model.result.RecentStudyItemEntity;
import com.example.lancooznbk.presenter.RecentStudyPresenter;

import com.example.lancooznbk.utils.DataCleanManager;
import com.example.lancooznbk.utils.DialogHelper;
import com.example.lancooznbk.view.activity.SystemHelperActivity;
import com.example.lancooznbk.view.adapter.HeaderBottomAdapter;
import com.example.lancooznbk.view.adapter.ListMenuOneAdapter;
import com.example.lancooznbk.view.adapter.ListMenuTwoAdapter;
import com.example.lancooznbk.view.base.ILoadDataView;
import com.example.lancooznbk.view.base.ZnbkBaseMainFragment;
import com.example.lancooznbk.view.widget.CircleImageView;
import com.example.lancooznbk.view.widget.CustomDialog;
import com.example.lancooznbk.view.widget.DisciplinePopWindow;
import com.example.lancooznbk.view.widget.LineChartView;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.lancoo.cpbase.authentication.activities.LoginActivity;
import com.lancoo.cpbase.authentication.base.LoginOperate;
import com.lancoo.reviewsystem.utils.ToastUtils;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2018\2\6 0006.
 */

public class ZnbkMainFragment  extends ZnbkBaseMainFragment<RecentStudyPresenter> implements ILoadDataView<RecentStudyItemEntity> {


    /*
    * 左侧导航栏相关控件
    * */
    private CircleImageView mImgHead;
    private TextView mTvUserName;
    private TextView mTvUserClass;
    private TextView mTvUserNo;
    private LoginOperate mLoginOperate;
    private String strCacheSize;
    private TextView folding_TV ;
    /*
   * 主界面顶部标题栏学科切换
   * */
    private TextView mTvDicName;
    private ImageView mArrowIv;
    private DisciplinePopWindow mDisciplinePopWindow;

 /*   private DecoratorViewPager viewPager;
   */ private ArrayList<View> views = new ArrayList<>();/*
    private ArrayList<ImageView> pointImageView =new ArrayList<>();
    private ArrayList<View> LayoutInflaterList =new ArrayList<>();*/
    private View viewPagerscoring_background ;
    private View viewPagerlearning_process ;
    private View viewPagerability_to_change ;

    private View mView;
    private View mVmasker;
    private TextView mTvLoginOut;
    private SlidingMenu mMenu = null;
    private String[] menu_text={"清理缓存", "设置"};

    private List<String> SubjectName=new ArrayList<>();
    private List<String> SubjectID=new ArrayList<>();
    private List<String> BaseSubjectID=new ArrayList<>();
    private View mainView;
    private View mMenuView;
    private GridView head_titlesGV;

    private RelativeLayout shadowRL;
    public LinearLayout shadowLL;

    /*
    * Recycler相关
    * */
    private RecyclerView mRecyclerView;
    private RelativeLayout folding_RLY;
    private ImageView folding_Bg;
    private HeaderBottomAdapter mHeaderBottomAdapter;
    LinearLayoutManager layoutManager;

//    private XRefreshView mXRefreshView;

    private AppBarLayout mAppBarLayout;
    private CollapsingToolbarLayout collapsingToolbarLayout;


    RecentStudyItemEntity mRecentStudyItemEntity;

    private TextView mTvDisChinese;
    private TextView mTvDisMathematics;
    private TextView mTvDisEnglish;
    private TextView mTvDisChemical;
    private TextView mTvDisPhysical;
    private TextView mTvDisBiological;
    private TextView mTvDisGeographic;
    private TextView mTvDisHistory;
    private TextView mTvDisPolitical;

    private Drawable top;
    private ClickListenerInterface clickListenerInterface;
    private TextView mTvDisNameA;

    public interface ClickListenerInterface {
        public void doChangeSubject(String subjectName);
    }
    @Override
    public void loadData(RecentStudyItemEntity data) {
        mRecentStudyItemEntity = data;
//        if (mRecyclerView.getLayoutManager() != null) {
//            mRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);
//        }
        setViewPagerData(mRecentStudyItemEntity);
        if (ZnbkBasehandler != null) {
            Log.e("aaaaa","aa1111");
            ZnbkBasehandler.removeCallbacks(ZnbkBaserunnable);
            mXRefreshView.stopRefresh();
        }
        if (startRefreshhandler != null ){
            Log.e("aaaaa","aa1111");
            startRefreshhandler.removeCallbacks(ZnbkBaserunnable);
            mXRefreshView.stopRefresh();
        }
        Log.e("===loadData===", "===mRecentStudyItemEntity===" + data.getPredictInfo().getPredictDate());
    }

 /*   @Override
    public void loadMoreData(RecentStudyItemEntity data) {
        mRecentStudyItemEntity = data;
        if (mRecyclerView.getLayoutManager() != null) {
            mRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);
        }
        setViewPagerData(mRecentStudyItemEntity);
        Log.e("===loadMoreData===", "===11111===" + data.getLastAnswer().size());
        mXRefreshView.stopLoadMore();
    }
*/
    @Override
    public void initBaseMainViews(final View view, Bundle savedInstanceState) {
        mainView= view;
        Log.e("aaaaaaaaaa","initBaseMainViews");
        mPresenter = new RecentStudyPresenter(this);
        Log.e("mPresenter","111111"+mPresenter);
        /*
        * 左侧侧滑导航栏
        * */
        mView = getHolderActivity().getLayoutInflater().inflate(R.layout.main_menu_login, null, false);
        mImgHead = (CircleImageView) mView.findViewById(R.id.img_userHead);
        mTvUserName = (TextView) mView.findViewById(R.id.tv_userName);
        mTvUserClass = (TextView) mView.findViewById(R.id.tv_userClass);
        mTvUserNo = (TextView) mView.findViewById(R.id.tv_userNo);

        Glide.with(this).load(UserInfo.PhotoUrl).skipMemoryCache(false).error(R.mipmap.img_head_default).into(mImgHead);
        mTvUserName.setText(UserInfo.StuName);
        mTvUserClass.setText(UserInfo.ClassName);
        mTvUserNo.setText(UserInfo.StuId);

        mLoginOperate = new LoginOperate(getHolderActivity());
        mTvLoginOut = (TextView) mView.findViewById(R.id.tv_login_out);
        mTvLoginOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("mTvLoginOut","onClick1");
                mLoginOperate.logOut();
                startActivity(new Intent(getHolderActivity(), LoginActivity.class));
                getHolderActivity().finish();
            }
        });

         /*
        * 学科切换
        * */
        mArrowIv = (ImageView) view.findViewById(R.id.iv_arrow);
        mVmasker = (View) view.findViewById(R.id.view_masker);
        mTvDicName = (TextView) view.findViewById(R.id.tv_discipline_name);
        ImageView mImageView=(ImageView) view.findViewById(R.id.iv_personal_icon);
        mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMenu.showMenu();
            }
        });
    /*    mTvDicName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("mTvDicName","onClick2");
                mDisciplinePopWindow = new DisciplinePopWindow(getHolderActivity(), mTvDicName, mArrowIv, view);
                mDisciplinePopWindow.setClippingEnabled(false);//使popupwindow显示为全屏
                mDisciplinePopWindow.showAtLocation(mArrowIv, Gravity.TOP, 0, 10);
            }
        });*/
//        ListView Home_listView=(ListView)view.findViewById(R.id.home_listView);
      /*  View layout_main_interface_menu = View.inflate(getHolderActivity(), R.layout.layout_main_interface_menu, null);
        View home_recyclerview = View.inflate(getHolderActivity(), R.layout.home_recyclerview, null);*/
//        Home_listView.setAdapter(new Home_listViewAdapter(getHolderActivity()));
        Log.e("aaaaaaaaaa","initBaseMainViews3");
//        mXRefreshView.addView(layout_main_interface_menu);
//        mXRefreshView.addView(home_recyclerview);
//        ListViewAdapter listViewAdapter = new ListViewAdapter(getHolderActivity(),);


        /*
        * Recycler
        * */
        mRecyclerView = (RecyclerView) view.findViewById(R.id.rv_main);
        folding_RLY = (RelativeLayout) view.findViewById(R.id.folding_RLY);
        folding_Bg = (ImageView) view.findViewById(R.id.folding_Bg);
        folding_TV = (TextView) view.findViewById(R.id.folding_TV);
       // folding_Bg.getBackground().setAlpha(100);
        //List布局
        layoutManager=new LinearLayoutManager(getHolderActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
//        layoutManager.setOrientation(mRecyclerView);
        mRecyclerView.setLayoutManager(layoutManager);
        views.clear();
        viewPagerscoring_background = View.inflate(getHolderActivity(), R.layout.scoring_background, null);
        viewPagerlearning_process = View.inflate(getHolderActivity(), R.layout.learning_process, null);
        viewPagerability_to_change = View.inflate(getHolderActivity(), R.layout.ability_to_change, null);
        views.add(viewPagerscoring_background);
        views.add(viewPagerlearning_process);
        views.add(viewPagerability_to_change);
        mHeaderBottomAdapter = new HeaderBottomAdapter(getHolderActivity(),null,views,folding_TV);
        mRecyclerView.setAdapter(mHeaderBottomAdapter);
        mRecyclerView.addItemDecoration(new DividerItemDecoration(getHolderActivity(), DividerItemDecoration.VERTICAL));
        mRecyclerView.setPadding(0, 0, 0, 0);
        mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                Log.e("onScrollStateChanged","+newState"+newState);
            }
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                Log.e("dx+dy","dx+" + dx + "+dy+"+dy);
                Log.e("onScrolled","+viewPagerscoring_background.getHeight()+"+viewPagerscoring_background.getHeight());
                Log.e("onScrolled","+getScollYDistance+"+getScollYDistance());
                /*dy > 0为上拉显示，dy < 0为下拉隐藏*/
                if (dy > 0){
                    if (getScollYDistance()>=450){
                        folding_RLY.setVisibility(View.VISIBLE);
                    }
                }else if(dy < 0){
                    if (getScollYDistance()<450){
                        folding_RLY.setVisibility(View.GONE);
                    }
                }
            }
        });

        shadowRL = (RelativeLayout) view.findViewById(R.id.shadowRL);
        shadowLL = (LinearLayout) view.findViewById(R.id.shadowLL);
        shadowLL.setOnClickListener(new View.OnClickListener() {@Override public void onClick(View v) {}});
        shadowRL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                closeView();
            }
        });
        //下拉是刷新组件设置
//        mXRefreshView = (XRefreshView) view.findViewById(R.id.sr_layout);
//        mXRefreshView.setAutoRefresh(false);

//        控制下拉loading出现与消失
//        mAppBarLayout = (AppBarLayout) view.findViewById(R.id.appbar_layout);
//        mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
//            @Override
//            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
//
//                if (verticalOffset >= 0) {
//                    mXRefreshView.setEnabled(true);
//                } else {
//                    mXRefreshView.setEnabled(false);
//                }
//            }
//        });
        initMenu(view);
//        initRightView(view);
       // initToolbar(view);
        Log.e("aaaaaaaaaa","initBaseMainViews1");

    }

    public int getScollYDistance() {
        LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
        int position = layoutManager.findFirstVisibleItemPosition();
        View firstVisiableChildView = layoutManager.findViewByPosition(position);
        int itemHeight = firstVisiableChildView.getHeight();
        Log.e("getScollYDistance","+firstVisiableChildView+"+firstVisiableChildView);
        Log.e("getScollYDistance","+itemHeight+"+itemHeight);
        return (position) * itemHeight - firstVisiableChildView.getTop();
    }

    public class Home_listViewAdapter extends BaseAdapter {
        public Context mContext;
        public LayoutInflater mInflater;
        public Home_listViewAdapter(Context mContext) {
            Log.e("Home_listViewAdapter","Home_listViewAdapter");
            this.mContext=mContext;
            mInflater = LayoutInflater.from(mContext);
        }

        @Override
        public int getCount() {
            Log.e("getCount","getCount");
            return 2;
        }

        @Override
        public Object getItem(int i) {
            Log.e("getItem","getItem");
            return null;
        }

        @Override
        public long getItemId(int i) {
            Log.e("getItemId","getItemId");
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup){
            RelativeLayout viewPagerRLy;
            ViewHolder1 viewHolder1 = null;
            ViewHolder2 viewHolder2 = null;
            int viewType =getItemViewType(i);
            if (view ==null){
                switch (viewType) {
                    case 0:
                        view= mInflater.inflate(R.layout.layout_main_interface_menu,null);
                        viewHolder1 = new ViewHolder1();
                        viewHolder1.viewPagerRLy= (RelativeLayout)view.findViewById(R.id.viewPagerRLy);
                        view.setTag(viewHolder1);
                       break;
                    case 1:
                        view= mInflater.inflate(R.layout.home_recyclerview,null);
                        viewHolder2 = new ViewHolder2();
                        viewHolder2.viewPagerRLy= (RecyclerView)view.findViewById(R.id.rv_main);
                        view.setTag(viewHolder2);
                        break;
                }
            }
            return view;
        }
        class ViewHolder1{
            TextView tv;
            RelativeLayout viewPagerRLy;
        }
        class ViewHolder2{
            TextView tv2;
            RecyclerView viewPagerRLy;
        }
    }

   /*  public void setViewPager(View view){
        viewPager = (DecoratorViewPager) view.findViewById(R.id.viewPager);
        ImageView ImageView3 =(ImageView) view.findViewById(R.id.ImageView3);
        ImageView ImageView2 =(ImageView) view.findViewById(R.id.ImageView2);
        ImageView ImageView1 =(ImageView) view.findViewById(R.id.ImageView1);
        pointImageView.add(ImageView1);
        pointImageView.add(ImageView2);
        pointImageView.add(ImageView3);
        //载入图片资源ID
        viewPagerscoring_background = View.inflate(getHolderActivity(), R.layout.scoring_background, null);
        viewPagerlearning_process = View.inflate(getHolderActivity(), R.layout.learning_process, null);
        viewPagerability_to_change = View.inflate(getHolderActivity(), R.layout.ability_to_change, null);
        views.add(viewPagerscoring_background);
        views.add(viewPagerlearning_process);
        views.add(viewPagerability_to_change);

        MyAdapter pagerAdapter=new MyAdapter();
        viewPager.setNestedpParent((DecoratorXRefreshView)view.findViewById(R.id.xrv));
        //绑定适配器
       viewPager.setAdapter(pagerAdapter);
        //设置viewPager的初始界面为第一个界面
        viewPager.setCurrentItem(0);
        setImageBackground(0);
        viewPager.addOnPageChangeListener(new MyOnPageChangeListener());
    }*/


    @Override
    protected void updateViews(boolean isShowLoading) {
        mPresenter.getData(isShowLoading);
    }

    @Override
    public int attachLayoutRes() {
        return R.layout.znbk_slidingmenu_main;
    }


/*    private void initRightView(final View view) {

        ImageView mImageView = (ImageView) view.findViewById(R.id.iv_personal_icon);
        mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("mImageView","onClick3");
                mMenu.showMenu();
            }
        });

         *//*
        * 学科切换
        * *//*
        mArrowIv = (ImageView) view.findViewById(R.id.iv_arrow);
        mVmasker = (View) view.findViewById(R.id.view_masker);
        mTvDicName = (TextView) view.findViewById(R.id.tv_discipline_name);
        mTvDicName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("mTvDicName","onClick4");
                mDisciplinePopWindow = new DisciplinePopWindow(getHolderActivity(), mTvDicName, mArrowIv, view);
                mDisciplinePopWindow.setClippingEnabled(false);//使popupwindow显示为全屏
                mDisciplinePopWindow.showAtLocation(mArrowIv, Gravity.TOP, 0, 10);
            }
        });


    }*/

    /*
* 初始化侧滑功能
* */
    private void initMenu(View view) {
        mMenu = (SlidingMenu) view.findViewById(R.id.slidingmenulayout);
        mMenu.setMode(SlidingMenu.LEFT);
        // 设置触摸屏幕的模式
        mMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
        //获取屏幕宽高
        DisplayMetrics dm = new DisplayMetrics();
        getHolderActivity().getWindowManager().getDefaultDisplay()  .getMetrics(dm);
        // 设置滑动菜单视图的宽度
        mMenu.setBehindWidth(dm.widthPixels * 4 / 5);
        // 设置渐入渐出效果的值
        mMenu.setFadeDegree(0.35f);
        mMenu.setMenu(mView);
        initLeftListView(mView);//初始化侧边视图

        mMenu.setOnOpenListener(new SlidingMenu.OnOpenListener() {
            @Override
            public void onOpen() {
                Log.e("setOnOpenListener","onOpen");
                mVmasker.setVisibility(View.VISIBLE);
            }
        });

        mMenu.setOnClosedListener(new SlidingMenu.OnClosedListener() {
            @Override
            public void onClosed() {
                Log.e("setOnOpenListener","onOpen");
                mVmasker.setVisibility(View.GONE);
            }
        });

    }

    private void initLeftListView(View view) {
        ListView listView1 = (ListView) view.findViewById(R.id.listview_menu);
        listView1.setAdapter(new ListMenuOneAdapter(getHolderActivity()));
        listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                switch (i) {
                    case 0:
                        ToastUtils.showShort("点击了 id=" + i);
                        break;
                    case 1:
                        ToastUtils.showShort("点击了 id=" + i);
                        break;
                    case 2:
                        ToastUtils.showShort("点击了 id=" + i + "系统说明");
                        SystemHelperActivity.launch(getHolderActivity());
                        break;
                }
            }
        });


        ListView listView2 = (ListView) view.findViewById(R.id.listview_menu_two);
        listView2.setAdapter(new ListMenuTwoAdapter(getHolderActivity()));
        listView2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                switch (i) {
                    case 0:
                        ToastUtils.showShort("点击了 id=" + i + "清理缓存");
                        try {
                            strCacheSize = DataCleanManager.getCacheSize(getHolderActivity());
                        } catch (Exception e) {
                            e.printStackTrace();
                            strCacheSize = "系统异常！";
                        }

                        DialogHelper.cleanCacheDialog(getHolderActivity(), strCacheSize, new CustomDialog.OnCustomClickListener() {
                            @Override
                            public void onClick() {
                                DataCleanManager.cleanInternalCache(getHolderActivity());
                            }
                        });
                        break;
                    case 1:
                        ToastUtils.showShort("点击了 id=" + i);
                        break;
                }
            }
        });

    }


    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     */
    private int dip2px(float dpValue) {
        final float scale = getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }


    public Handler startRefreshhandler= new Handler();
    public Runnable startRefreshrunnable = new Runnable() {
        public void run() {
            Log.e("ZnbkBaserunnable","ZnbkBaserunnable+");
            mXRefreshView.stopRefresh();
        }
    };

    public void setViewPagerData(RecentStudyItemEntity Data) {
        TextView DoData = (TextView) viewPagerscoring_background.findViewById(R.id.DnData);
        /*Log.e("setViewPagerData","DoData+"+DoData);*/
         TextView PredictionscoreTV = (TextView) viewPagerscoring_background.findViewById(R.id.PredictionscoreTV);
         TextView FullMarksTV = (TextView) viewPagerscoring_background.findViewById(R.id.FullMarksTV);
         TextView Class_rankTV = (TextView) viewPagerscoring_background.findViewById(R.id.Class_rankTV);
         TextView Grade_rankedTV = (TextView) viewPagerscoring_background.findViewById(R.id.Grade_rankedTV);
         TextView EvaluationTimeTV = (TextView) viewPagerscoring_background.findViewById(R.id.EvaluationTimeTV);
         TextView learning_processTV = (TextView) viewPagerlearning_process.findViewById(R.id.learning_processTV);
         LineChartView LineChartViewID = (LineChartView) viewPagerability_to_change.findViewById(R.id.chartView1);
        TextView data_TextView  = (TextView) viewPagerability_to_change.findViewById(R.id.data_TextView);
         double PredictScoreDate = Data.getPredictInfo().getPredictScore();
         String PredictDate = Data.getPredictInfo().getPredictDate();

         double FullScoreDate = Data.getPredictInfo().getFullScore();
        List<RecentStudyItemEntity.LastAnswerBean>  LastAnswerDate = Data.getLastAnswer();
        List<RecentStudyItemEntity.SubjectInfoBean>  SubjectInfoData = Data.getSubjectInfo();
        double CurrentClassRankDate = Data.getPredictInfo().getCurrentClassRank();
        double OriginalClassRankDate = Data.getPredictInfo().getOriginalClassRank();
        double CurrentGradeRankDate = Data.getPredictInfo().getCurrentGradeRank();
        double OriginalGradeRankDate = Data.getPredictInfo().getOriginalGradeRank();
        double learningProcessDate = Data.getProcess();
        if (PredictScoreDate / FullScoreDate < 0.6){
            DoData.setVisibility(View.VISIBLE);
            PredictionscoreTV.setText("");
            folding_TV.setText("预测得分:0.0");
        }else{
            DoData.setVisibility(View.INVISIBLE);
            PredictionscoreTV.setText(String.valueOf((float)((int)(PredictScoreDate*10))/10));
            folding_TV.setText("预测得分:"+ String.valueOf((float)((int)(PredictScoreDate*10))/10));
        }
        FullMarksTV.setText("(满分:"+ (float)((int)(PredictScoreDate*10))/10 +")");

//        Class_rankTV.setText("班级排名:"+ CurrentClassRankDate);
        if (CurrentClassRankDate < OriginalClassRankDate){
            String CurrentClassRankDate1 = "班级排名:"+ (int)CurrentClassRankDate;
            String CurrentClassRankDate2 = "" +(int)(OriginalClassRankDate -CurrentClassRankDate);
            String fromHtml1 ="<font color=\'#FFFFFF\'>"+ CurrentClassRankDate1 +"</font><font color=\'#ff0000\'>↓</font><font color=\'#FFFFFF\'>" +CurrentClassRankDate2+"</font>";
            Class_rankTV.setText(Html.fromHtml(fromHtml1));
        }else{
            String CurrentClassRankDate1 = "班级排名:"+ (int)CurrentClassRankDate;
            String CurrentClassRankDate2 = "" +(int)(CurrentClassRankDate -OriginalClassRankDate);
            String fromHtml1 ="<font color=\'#FFFFFF\'>"+ CurrentClassRankDate1 +"</font><font color=\'#4eff00\'>↑</font><font color=\'#FFFFFF\'>" +CurrentClassRankDate2+"</font>";
            Class_rankTV.setText(Html.fromHtml(fromHtml1));
        }

        if (CurrentGradeRankDate >=OriginalGradeRankDate) {
            String CurrentGradeRankDate1 = "年级排名:" + (int) CurrentGradeRankDate;
            String CurrentGradeRankDate2 = "" + (int) (CurrentGradeRankDate - OriginalGradeRankDate);
            String fromHtml1 = "<font color=\'#FFFFFF\'>" + CurrentGradeRankDate1 + "</font><font color=\'#4eff00\'>↑</font><font color=\'#FFFFFF\'>" + CurrentGradeRankDate2 + "</font>";
            Grade_rankedTV.setText(Html.fromHtml(fromHtml1));
        }else{
            String CurrentGradeRankDate1 = "年级排名:" + (int) CurrentGradeRankDate;
            String CurrentGradeRankDate2 = "" + (int) (CurrentGradeRankDate - OriginalGradeRankDate);
            String fromHtml1 = "<font color=\'#FFFFFF\'>" + CurrentGradeRankDate1 + "</font><font color=\'#4eff00\'>↓</font><font color=\'#FFFFFF\'>" + CurrentGradeRankDate2 + "</font>";
            Grade_rankedTV.setText(Html.fromHtml(fromHtml1));
        }
        EvaluationTimeTV.setText( PredictDate);
        learning_processTV.setText(String.valueOf((float)((int)(learningProcessDate*10))/10 ));
        List<PointF> pointFs = new ArrayList<PointF>();
        String[] index_x=new String[Data.getWeekRecordList().size()];
        /*为折叠提供数据*/
        if (Data.getWeekRecordList() != null && Data.getWeekRecordList().size() != 0 ){
        for (int i=0;Data.getWeekRecordList().size()>i;i++){
            Log.e("WeekRecordList", "WeekRecordList+" );
//            Double a=Double.parseDouble(Data.getWeekRecordList().get(i).getScore()+"1");
//            String b =new DecimalFormat("#.0").format(a);
//            Float c =Float.parseFloat(b);
            Float c=(float)((int)(Data.getWeekRecordList().get(i).getScore()*10))/10;
            pointFs.add(new PointF(0.5F+i*1F,c*1F));
            String[] sourceStrArray = Data.getWeekRecordList().get(i).getRecordTime().split("-");
            String getRecordTimeData =sourceStrArray[1] +"."+sourceStrArray[2];
            index_x[i]= getRecordTimeData;

            if (Data.getWeekRecordList().size() -1 == i){
                data_TextView.setText(String.valueOf((float)((int)(Data.getWeekRecordList().get(i).getScore()*10))/10));
            }
        }
            LineChartViewID.setData(pointFs, "X轴提示文字", "Y轴提示文字",getHolderActivity(),index_x);
        }
        mHeaderBottomAdapter.removeData(2);
        mHeaderBottomAdapter.addData(2, LastAnswerDate);

        SubjectName.clear();
        SubjectID.clear();
        for (int i=0; i< SubjectInfoData.size(); i++ ){
            SubjectName.add(SubjectInfoData.get(i).getSubjectName());
            SubjectID.add(SubjectInfoData.get(i).getTKSubjectID());
            BaseSubjectID.add(SubjectInfoData.get(i).getBaseSubjectID());
        }
        if (SubjectName != null) {

            mTvDicName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (shadowLL.getVisibility() != View.VISIBLE) {
                        PopWindowsInitView();
                        ShowView();
                    }else{
                        closeView();
                    }
                }
            });
        }
    }

    private void PopWindowsInitView(){
        mTvDisChinese = (TextView) shadowLL.findViewById(R.id.tv_chinese);
        mTvDisMathematics = (TextView) shadowLL.findViewById(R.id.tv_mathematics);
        mTvDisEnglish = (TextView) shadowLL.findViewById(R.id.tv_english);
        mTvDisChemical = (TextView) shadowLL.findViewById(R.id.tv_chemical);
        mTvDisPhysical = (TextView) shadowLL.findViewById(R.id.tv_physical);
        mTvDisBiological = (TextView) shadowLL.findViewById(R.id.tv_biological);
        mTvDisGeographic = (TextView) shadowLL.findViewById(R.id.tv_geographic);
        mTvDisHistory = (TextView) shadowLL.findViewById(R.id.tv_history);
        mTvDisPolitical = (TextView) shadowLL.findViewById(R.id.tv_political);

        clickChinese();
        clickMathematics();
        clickEnglish();
        clickChemical();
        clickPhysical();
        clickBiological();
        clickGeographic();
        clickHistory();
        clickPolitical();
        setData();
    }

    private void  setData(){
        for (int i=0;i< SubjectName.size();i++ ){
            Log.e("setData","head_titles.get(i)+"+SubjectName.get(i));
            if (i==0){
                setContent(mTvDisChinese,SubjectName.get(i),SubjectID.get(i));
                mTvDisChinese.setVisibility(View.VISIBLE);
            }else if (i==1){
                setContent(mTvDisMathematics,SubjectName.get(i),SubjectID.get(i));
                mTvDisMathematics.setVisibility(View.VISIBLE);
            }else if (i==2){
                setContent(mTvDisEnglish,SubjectName.get(i),SubjectID.get(i));
                mTvDisEnglish.setVisibility(View.VISIBLE);
            }else if (i==3){
                setContent(mTvDisChemical,SubjectName.get(i),SubjectID.get(i));
                mTvDisChemical.setVisibility(View.VISIBLE);
            }else if (i==4){
                setContent(mTvDisPhysical,SubjectName.get(i),SubjectID.get(i));
                mTvDisPhysical.setVisibility(View.VISIBLE);
            }else if (i==5){
                setContent(mTvDisBiological,SubjectName.get(i),SubjectID.get(i));
                mTvDisBiological.setVisibility(View.VISIBLE);
            }else if (i==6){
                setContent(mTvDisGeographic,SubjectName.get(i),SubjectID.get(i));
                mTvDisGeographic.setVisibility(View.VISIBLE);
            }else if (i==7){
                setContent(mTvDisHistory,SubjectName.get(i),SubjectID.get(i));
                mTvDisHistory.setVisibility(View.VISIBLE);
            }else if (i==8){
                setContent(mTvDisPolitical,SubjectName.get(i),SubjectID.get(i));
                mTvDisPolitical.setVisibility(View.VISIBLE);
            }
        }
    }

    private void  setContent( TextView ContentTV, String dataName, String subjectID){
        top=null;
        Resources res = ContentTV.getResources();
        ContentTV.setText(dataName);
        if (dataName.equals("语文")){
            top = res.getDrawable(R.drawable.selector_btn_discipline_chinese);
            ContentTV.setCompoundDrawablesWithIntrinsicBounds(null, top , null, null);
        }else if (dataName.equals("数学")){
            top = res.getDrawable(R.drawable.selector_btn_discipline_mathematics);
            ContentTV.setCompoundDrawablesWithIntrinsicBounds(null, top , null, null);
        }else if (dataName.equals("英语")){
            top = res.getDrawable(R.drawable.selector_btn_discipline_english);
            ContentTV.setCompoundDrawablesWithIntrinsicBounds(null, top , null, null);
        }else if (dataName.equals("化学")){
            top = res.getDrawable(R.drawable.selector_btn_discipline_chemical);
            ContentTV.setCompoundDrawablesWithIntrinsicBounds(null, top , null, null);
        }else if (dataName.equals("物理")){
            top = res.getDrawable(R.drawable.selector_btn_discipline_physical);
            ContentTV.setCompoundDrawablesWithIntrinsicBounds(null, top , null, null);
        }else if (dataName.equals("生物")){
            top = res.getDrawable(R.drawable.selector_btn_discipline_biological);
            ContentTV.setCompoundDrawablesWithIntrinsicBounds(null, top , null, null);
        }else if (dataName.equals("地理")){
            top = res.getDrawable(R.drawable.selector_btn_discipline_geographic);
            ContentTV.setCompoundDrawablesWithIntrinsicBounds(null, top , null, null);
        }else if (dataName.equals("历史")){
            top = res.getDrawable(R.drawable.selector_btn_discipline_history);
            ContentTV.setCompoundDrawablesWithIntrinsicBounds(null, top , null, null);
        }else if (dataName.equals("政治")){
            top = res.getDrawable(R.drawable.selector_btn_discipline_political);
            ContentTV.setCompoundDrawablesWithIntrinsicBounds(null, top , null, null);
        }

    }

    public void setClicklistener(ClickListenerInterface clickListenerInterface) {
        this.clickListenerInterface = clickListenerInterface;
    }


    private void getSubjectInfo(int index){
        UserInfo.BaseSubjectID =  BaseSubjectID.get(index);
        UserInfo.SubjectId = SubjectID.get(index);
        UserInfo.SubjectName = SubjectName.get(index);
    }

    /*
    * 语文
    * */
    private void clickChinese(){
        mTvDisChinese.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                getSubjectInfo(0);

                mTvDicName.setText(mTvDisChinese.getText());
//                clickListenerInterface.doChangeSubject(SubjectID.get(0));
                getHttpData(SubjectID.get(0));
                closeView();
            }
        });

    }

    /*
    * 数学
    * */
    private void clickMathematics(){
        mTvDisMathematics.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                getSubjectInfo(1);

                mTvDicName.setText(mTvDisMathematics.getText());
//                clickListenerInterface.doChangeSubject(SubjectID.get(1));
                getHttpData(SubjectID.get(1));
                closeView();
            }
        });

    }

    /*
    * 英语
    * */
    private void clickEnglish(){
        mTvDisEnglish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                getSubjectInfo(2);

                mTvDicName.setText(mTvDisEnglish.getText());
//                clickListenerInterface.doChangeSubject(SubjectID.get(2));
                getHttpData(SubjectID.get(2));
                closeView();
            }
        });

    }

    /*
    * 物理
    * */
    private void clickBiological(){
        mTvDisBiological.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                getSubjectInfo(4);

                mTvDicName.setText(mTvDisBiological.getText());
//                clickListenerInterface.doChangeSubject(SubjectID.get(4));
                getHttpData(SubjectID.get(4));
                closeView();
            }
        });

    }

    /*
    * 化学
    * */
    private void clickChemical(){
        mTvDisChemical.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                getSubjectInfo(3);

                mTvDicName.setText(mTvDisChemical.getText());
//                clickListenerInterface.doChangeSubject(SubjectID.get(3));
                getHttpData(SubjectID.get(3));
                closeView();
            }
        });

    }



    /*
    * 生物
    * */
    private void clickPhysical(){
        mTvDisPhysical.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                getSubjectInfo(5);

                mTvDicName.setText(mTvDisPhysical.getText());
//                clickListenerInterface.doChangeSubject(SubjectID.get(5));
                getHttpData(SubjectID.get(5));
                closeView();
            }
        });

    }

    /*
   * 政治
   * */
    private void clickPolitical(){
        mTvDisPolitical.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                getSubjectInfo(8);

                mTvDicName.setText(mTvDisPolitical.getText());
//                clickListenerInterface.doChangeSubject(SubjectID.get(8));
                getHttpData(SubjectID.get(8));
                closeView();
            }
        });

    }

    /*
    * 历史
    * */
    private void clickHistory(){
        mTvDisHistory.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                getSubjectInfo(7);

                mTvDicName.setText(mTvDisHistory.getText());
//                clickListenerInterface.doChangeSubject(SubjectID.get(7));
                closeView();
                getHttpData(SubjectID.get(7));
            }
        });

    }

    /*
    * 地理
    * */
    private void clickGeographic(){
        mTvDisGeographic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                getSubjectInfo(6);

                mTvDicName.setText(mTvDisGeographic.getText());
//                clickListenerInterface.doChangeSubject(SubjectID.get(6));
                closeView();
                getHttpData(SubjectID.get(6));
            }
        });
    }

    private void  getHttpData(String subjectName){
        mXRefreshView.startRefresh();
        startRefreshhandler.postDelayed(startRefreshrunnable ,20000);
        mPresenter.getDataByStatus(subjectName);
    }

    public void closeView(){
        Animation btn_rotate_anim = AnimationUtils.loadAnimation(getHolderActivity(),R.anim.btn_rotate_anim_2);
        btn_rotate_anim.setFillAfter(true);
        mArrowIv.startAnimation(btn_rotate_anim);
        shadowLL.startAnimation(AnimationUtils.loadAnimation(getHolderActivity(),R.anim.anim_zoomin_out));
        shadowRL.setVisibility(View.GONE);
        shadowLL.setVisibility(View.GONE);
//        mArrowIv.startAnimation(AnimationUtils.loadAnimation(getHolderActivity(),R.anim.btn_rotate_anim_2));
        /*mTvDisChinese.setVisibility(View.GONE);
        mTvDisMathematics.setVisibility(View.GONE);
        mTvDisEnglish.setVisibility(View.GONE);
        mTvDisChemical.setVisibility(View.GONE);
        mTvDisPhysical.setVisibility(View.GONE);
        mTvDisBiological.setVisibility(View.GONE);
        mTvDisGeographic.setVisibility(View.GONE);
        mTvDisHistory.setVisibility(View.GONE);
        mTvDisPolitical.setVisibility(View.GONE);*/
    }

    private void ShowView(){
        Animation btn_rotate_anim = AnimationUtils.loadAnimation(getHolderActivity(),R.anim.btn_rotate_anim_1);
        btn_rotate_anim.setFillAfter(true);
        mArrowIv.startAnimation(btn_rotate_anim);
        shadowLL.startAnimation(AnimationUtils.loadAnimation(getHolderActivity(),R.anim.anim_zoomin));
        shadowLL.setVisibility(View.VISIBLE);
        shadowRL.setVisibility(View.VISIBLE);
    }


}
